const models = require("../db/mysqldb/index");

class DataSystemUserPostModel {
  /**
   * @description 批量删除
   * @param {*} role_id
   * @returns
   */
  static async deleteByPostId(role_id) {
    return await models.sys_user_post.destroy(
      {
        where: { role_id },
      }
    );
  }
  /**
   * @description 批量删除
   * @param {*} user_id
   * @returns
   */
   static async deleteByUserId({user_id}) {
    return await models.sys_user_post.destroy(
      {
        where: { user_id },
      }
    );
  }
  /**
   * @description 批量插入
   * @param {*} data
   * @returns
   */
  static async bulkCreate(data) {
    return await models.sys_user_post.bulkCreate(data);
  }

  /**
   * @description 获取所有
   * @param {*} data
   * @returns
   */
  static async all() {
    return await models.sys_user_post.findAll();
  }

  /**
   * @description 当前用户的岗位信息
   * @param {*} user_id
   * @returns
   */
  static async findPostInfoByUserID(user_id) {
    let sql = `select sp.post_id,
    sp.post_name,
    sp.post_code,
    sp.post_sort,
    sp.status,
    sp.remark
    from sys_user_post sup LEFT JOIN sys_post sp on sup.post_id = sp.post_id where user_id = ${user_id} and sp.del_flag = '0'`;
    return await models.sequelize.query(sql, {
      replacements: ["active"],
      type: models.sequelize.QueryTypes.SELECT,
    });
  }
}
module.exports = {
  DataSystemUserPostModel,
};
